<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="文件id" prop="fileId">
        <el-input
          v-model="queryParams.fileId"
          placeholder="请输入文件id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="链接" prop="url">
        <el-input
          v-model="queryParams.url"
          placeholder="请输入链接"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标题" prop="tilte">
        <el-input
          v-model="queryParams.tilte"
          placeholder="请输入标题"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="价格" prop="money">
        <el-input
          v-model="queryParams.money"
          placeholder="请输入价格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类目" prop="type">
        <el-input
          v-model="queryParams.type"
          placeholder="请输入类目"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类目一" prop="type1">
        <el-input
          v-model="queryParams.type1"
          placeholder="请输入类目一"
          clearable
          @keyup.enter.native="handleQuery"
        />
<!--        <el-select v-model="formData.field101" placeholder="请选择下拉选择" clearable :style="{width: '100%'}">-->
<!--          <el-option v-for="(item, index) in field101Options" :key="index" :label="item.label"-->
<!--                     :value="item.value" :disabled="item.disabled">-->

<!--          </el-option>-->
<!--        </el-select>-->
      </el-form-item>
<!--      <el-form-item label="类目二" prop="type2">-->
<!--        <el-input-->
<!--          v-model="queryParams.type2"-->
<!--          placeholder="请输入类目二"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="类目三" prop="type3">-->
<!--        <el-input-->
<!--          v-model="queryParams.type3"-->
<!--          placeholder="请输入类目三"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="类目四" prop="type4">-->
<!--        <el-input-->
<!--          v-model="queryParams.type4"-->
<!--          placeholder="请输入类目四"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="类目五" prop="type5">-->
<!--        <el-input-->
<!--          v-model="queryParams.type5"-->
<!--          placeholder="请输入类目五"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="  利润标签" prop="states">
        <el-input
          v-model="queryParams.states"
          placeholder="请输入  利润标签"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button type="danger" plain icon="el-icon-delete" size="mini" @click="selectDelete">选择删除</el-button>
      </el-form-item>


<!--      <el-form-item label="类目一" prop="field101">-->
<!--        <el-select v-model="queryParams.type1" placeholder="请选择类目一" clearable :style="{width: '100%'}">-->
<!--          <el-option v-for="(item, index) in field101Options"-->
<!--                     :key="index" :label="item.label"-->
<!--                     :value="item.value"-->
<!--                     :disabled="item.disabled">-->
<!--          </el-option>-->
<!--        </el-select>-->
<!--      </el-form-item>-->

    </el-form>

    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label=" 店铺可上类目" prop="shop" label-width="96px">
        <el-select v-model="queryParams.shop" clearable>
          <el-option
            v-for="dict in shopNames"
            :key="dict.value"
            :label="dict"
            :value="dict"
          />
        </el-select>
      </el-form-item>

      <el-form-item label=" 全开选择" prop="choose" label-width="68px">
        <el-select v-model="queryParams.choose" clearable>
          <el-option
            v-for="dict in dict.type.choose"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

<!--      <el-form-item label=" 同行价格区间" prop="price_range_th" label-width="96px">-->
<!--        <el-select v-model="queryParams.price_range_th" clearable>-->
<!--          <el-option-->
<!--            v-for="dict in dict.type.price_range_th"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          />-->
<!--        </el-select>-->
<!--      </el-form-item>-->

<!--      <el-form-item label=" 爆款价格区间" prop="price_range_bk" label-width="96px">-->
<!--      <el-select v-model="queryParams.price_range_bk" clearable>-->
<!--        <el-option-->
<!--          v-for="dict in dict.type.price_range_bk"-->
<!--          :key="dict.value"-->
<!--          :label="dict.label"-->
<!--          :value="dict.value"-->
<!--        />-->
<!--      </el-select>-->
<!--    </el-form-item>-->


      <el-form-item label="  设置同行一级" prop="states" label-width="96px">
        <el-input
          v-model="queryParams.ThNumber"
          placeholder="请设置同行一级数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="  设置爆款一级" prop="states" label-width="96px">
        <el-input
          v-model="queryParams.BkNumber"
          placeholder="请设置爆款一级数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExportZip">导出ZIP</el-button>
      </el-form-item>



    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['violate:tilte:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['violate:tilte:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['violate:tilte:remove']"
        >删除</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['violate:tilte:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleImport"
          v-hasPermi="['violate:tilte:import']"
        >导入</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          @click="distinct"
          v-hasPermi="['violate:tilte:distinct']"
        >一键去重(链接，标题)</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleImportDelete"
          v-hasPermi="['violate:tilte:importDelete']"
        >导入删除模板</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          @click="handleDeleteAll"
          v-hasPermi="['violate:tilte:removeAll']"
        >一键全部删除（慎用）</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExportURL"
          v-hasPermi="['violate:tilte:urlexport']"
        >导出url删除模板</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExportTitle"
          v-hasPermi="['violate:tilte:export']"
        >导出标题删除模板</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="tilteList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="id" align="center" prop="id" />-->
      <el-table-column label="文件id" align="center" prop="fileId"/>
      <el-table-column label="链接" align="center" prop="url" />
      <el-table-column label="标题" align="center" prop="tilte" />
      <el-table-column label="价格" align="center" prop="money" />
      <el-table-column label="多级类目" align="center" prop="type" />
      <el-table-column label="类目一" align="center" prop="type1" />
      <el-table-column label="利润标签" align="center" prop="states" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:tilte:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:tilte:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="文件id" prop="fileId">
          <el-input v-model="form.fileId" placeholder="请输入文件id" />
        </el-form-item>
        <el-form-item label="链接" prop="url">
          <el-input v-model="form.url" placeholder="请输入链接" />
        </el-form-item>
        <el-form-item label="标题" prop="tilte">
          <el-input v-model="form.tilte" placeholder="请输入标题" />
        </el-form-item>
        <el-form-item label="价格" prop="money">
          <el-input v-model="form.money" placeholder="请输入价格" />
        </el-form-item>
        <el-form-item label="类目一" prop="type1">
          <el-input v-model="form.type1" placeholder="请输入类目一" />
        </el-form-item>
        <el-form-item label="类目二" prop="type2">
          <el-input v-model="form.type2" placeholder="请输入类目二" />
        </el-form-item>
        <el-form-item label="类目三" prop="type3">
          <el-input v-model="form.type3" placeholder="请输入类目三" />
        </el-form-item>
        <el-form-item label="类目四" prop="type4">
          <el-input v-model="form.type4" placeholder="请输入类目四" />
        </el-form-item>
        <el-form-item label="类目五" prop="type5">
          <el-input v-model="form.type5" placeholder="请输入类目五" />
        </el-form-item>
        <el-form-item label="  利润标签" prop="states">
          <el-input v-model="form.states" placeholder="请输入  利润标签" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <!-- 请输入导出条件 -->
    <el-dialog :title="title1" :visible.sync="open1" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
<!--        <el-form-item label="链接" prop="url">-->
<!--          <el-input v-model="form.url" placeholder="请输入链接" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="标题" prop="tilte">-->
<!--          <el-input v-model="form.tilte" placeholder="请输入标题" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="价格" prop="money">-->
<!--          <el-input v-model="form.money" placeholder="请输入价格" />-->
<!--        </el-form-item>-->
        <el-form-item label="类目" prop="type">
          <el-input v-model="form.type" placeholder="请输入类目一" label-width="50px" />
          <el-input v-model="form.type" placeholder="请输入类目一" />
        </el-form-item>
        <el-form-item label="类目一" prop="type1">
          <el-input v-model="form.type1" placeholder="请输入类目一" />
        </el-form-item>
        <el-form-item label="类目二" prop="type2">
          <el-input v-model="form.type2" placeholder="请输入类目二" />
        </el-form-item>
        <el-form-item label="类目三" prop="type3">
          <el-input v-model="form.type3" placeholder="请输入类目三" />
        </el-form-item>
        <el-form-item label="类目四" prop="type4">
          <el-input v-model="form.type4" placeholder="请输入类目四" />
        </el-form-item>
        <el-form-item label="类目五" prop="type5">
          <el-input v-model="form.type5" placeholder="请输入类目五" />
        </el-form-item>
        <el-form-item label="  利润标签" prop="states">
          <el-input v-model="form.states" placeholder="请输入  利润标签" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog
      :title="title2"
      :visible.sync="open2"
      width="500px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="文件路径">
          <file-upload v-model="form.filePath" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm2">确 定</el-button>
        <el-button @click="cancel2">取 消</el-button>
      </div>
    </el-dialog>

    <el-dialog
      :title="title3"
      :visible.sync="open3"
      width="500px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="文件路径">
          <file-upload v-model="form.filePath" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm3">确 定</el-button>
        <el-button @click="cancel3">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listTilte,
  getTilte,
  delTilte,
  addTilte,
  updateTilte,
  importTilte,
  fundistinct,
  importTilteDelete,
  delTilteAll,
  listShopName,
  selectDelete,
} from "@/api/violate/tilte";
import {importWords} from "@/api/violate/words";
import log from "@/views/monitor/job/log";

export default {
  name: "Tilte",
  dicts: ['shop', 'sys_user_sex','choose','price_range_th','price_range_bk'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      tilteList: [],
      shopNames: [] ,
      // 弹出层标题
      title: "",
      title1: "",
      title2: "",
      title3: "",
      // 是否显示弹出层
      open: false,
      open1: false,
      open2: false,
      open3: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fileId: null,
        url: null,
        tilte: null,
        money: null,
        type: null,
        type1: null,
        type2: null,
        type3: null,
        type4: null,
        type5: null,
        states: null,
        shop: null,
        choose: null,
        price_range_th: null,
        price_range_bk: null,
        ThNumber: null,
        BkNumber: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getShopNames() ;
  },
  methods: {
    /** 查询【SHopName】列表 */
    getShopNames() {
      this.loading = true;
      listShopName().then(response => {
        this.shopNames = response.rows;
        console.log("this.shopNames",this.shopNames) ;
        console.log("response",response) ;
      });
    },
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listTilte(this.queryParams).then(response => {
        this.tilteList = response.rows;
        console.log("this.tilteList",this.tilteList) ;
        this.total = response.total;
        this.loading = false;
      });
    },
    submitForm2() {
      importTilte(this.form).then((response) => {
        this.$modal.msgSuccess("导入成功");
        this.open2 = false;
        this.getList();
        this.getList();
      });
    },
    submitForm3() {
      importTilteDelete(this.form).then((response) => {
        this.$modal.msgSuccess("导入删除模板成功");
        this.open3 = false;
        this.getList();
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancel1() {
      this.open1 = false;
      this.reset();
    },
    cancel2() {
      this.open2 = false;
      this.reset();
    },
    cancel3() {
      this.open3 = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        fileId: null,
        url: null,
        tilte: null,
        money: null,
        type: null,
        type1: null,
        type2: null,
        type3: null,
        type4: null,
        type5: null,
        createBy: null,
        createTime: null,
        states: null,
        filePath: null,
      };
      this.resetForm("form");
    },
    // 表单重置
    reset1() {
      this.form = {
        url: null,
        tilte: null,
        money: null,
        type: null,
        type1: null,
        type2: null,
        type3: null,
        type4: null,
        type5: null,
        createBy: null,
        createTime: null,
        states: null,
        filePath: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 条件导出 */
    conditionExport() {
      this.reset();
      this.open1 = true;
      this.title1 = "条件【请填写导出条件】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTilte(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTilte(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTilte(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项？').then(function() {
        return delTilte(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 一键全删 */
    handleDeleteAll(row) {
      this.$modal.confirm('是否确认全部删除').then(function() {
        return delTilteAll();
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExportZip() {
      console.log(this.queryParams.shop);
      let shop = this.queryParams.shop ;
      if (shop == null){
         shop = "总表" ;
      }
      console.log(shop);
      this.download('violate/tilte/exportZip', {
        ...this.queryParams
      }, `${shop}_${new Date().getTime()}.zip`)
    },
    handleExport() {
      console.log(this.queryParams.shop);
      let shop = this.queryParams.shop ;
      if (shop == null){
        shop = "总表" ;
      }
      console.log(shop);
      this.download('violate/tilte/export', {
        ...this.queryParams
      }, `${shop}_${new Date().getTime()}.xlsx`)
    },
    /** 导出删除url模板操作 */
    handleExportURL() {
      this.download('violate/tilte/export/url', {
        ...this.queryParams
      }, `tilte_${new Date().getTime()}.xlsx`)
    },
    /** 导出删除标题模板操作 */
    handleExportTitle() {
      this.download('violate/tilte/export/title', {
        ...this.queryParams
      }, `tilte_${new Date().getTime()}.xlsx`)
    },
    handleImport() {
      this.open2 = true;
      this.title2 = "导入数据库";
    },
    handleImportDelete() {
      this.open3 = true;
      this.title3 = "导入删除模板";
    },
    //一键去重
    distinct(){
      this.$modal.confirm('是否确认一键去重').then(function() {
        return fundistinct();
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删去重成功");
      }).catch(() => {});
    },
    /** 选择删除 */
    selectDelete() {
      let queryParams = this.queryParams ;
      this.$modal.confirm('是否确认选择删除').then(function() {
       return selectDelete(queryParams);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("选择删除成功");
      }).catch(() => {});

      // selectDelete(this.queryParams).then(() => {
      //   this.getList();
      // });
    },
  }
};
</script>
